using System;

namespace Fusion.Utilities.Counters
{
    public class Counter
    {

        protected int count = 0;

        protected Action<int, int> action;

        protected bool negativable = false;

        public int Count1 { get => count; }

        public Counter()
        {
        }
        public Counter(bool negativable)
        {
            this.negativable = negativable;
        }

        public void AddAction(Action<int, int> action)
        {
            this.action += action;
        }
        public void RemoveAction(Action<int, int> action)
        {
            this.action -= action;
        }


        public void Count(int value)
        {
            count += value;
            if (!negativable && count < 0)
            {
                count = 0;
            }
            if (action != null)
            {
                action(count, value);
            }
        }

    }

}
